package com.ningxun.pagent.flow.service.impl;

import com.ningxun.pagent.common.core.domain.entity.SysUser;
import com.ningxun.pagent.common.utils.StringUtils;
import com.ningxun.pagent.system.service.ISysUserService;
import org.dromara.warm.flow.core.FlowEngine;
import org.dromara.warm.flow.core.dto.DefJson;
import org.dromara.warm.flow.core.dto.NodeJson;
import org.dromara.warm.flow.core.dto.PromptContent;
import org.dromara.warm.flow.core.listener.GlobalListener;
import org.dromara.warm.flow.core.listener.ListenerVariable;
import org.dromara.warm.flow.core.service.UserService;
import org.dromara.warm.flow.core.utils.MapUtil;
import org.dromara.warm.flow.ui.service.ChartExtService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Map;

public class ChartExtServiceImpl implements ChartExtService {
    /**
     * 扩展流程图
     * @param defJson 流程定义json对象
     */
    @Override
    public void execute(DefJson defJson) {
        defJson.setTopText("顶部提示信息: 比如流程名称" );
        defJson.getNodeList().forEach(nodeJson -> {
            // extMap是在分派监听器中设置的, 用户使用的时候不用局限于这种方式, 可以临时查询出来, 或者通过其他方式获取提示信息
            Map<String, Object> extMap = nodeJson.getExtMap();
            if (MapUtil.isNotEmpty(extMap)) {
                for(Map.Entry<String, Object> entry : extMap.entrySet()){
                    // 添加第二个条目
                    PromptContent.InfoItem item2 = new PromptContent.InfoItem();
                    item2.setPrefix(entry.getKey() + ": ");
                    item2.setContent((String) entry.getValue());
                    nodeJson.getPromptContent().getInfo().add(item2);
                }
            }
        });
    }
}

